package syyrjx.controller;

import syyrjx.jdbc.QuestionDB;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class DeleteQueServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.delete(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.delete(request, response);
    }

    private void delete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer id = Integer.valueOf(request.getParameter("id"));
        QuestionDB qbd = new QuestionDB();
        if(qbd.delete(id)){
            request.setAttribute("info","删除成功");
        }else{
            request.setAttribute("info","删除失败");
        }
        request.getRequestDispatcher("/queDelResult.jsp").forward(request,response);
    }
}
